package com.mhs.rssfeed;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;

import com.mhs.mhs_gui.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class RSSFeeder extends Activity{
	
	ArrayAdapter<String> aa;
	GridView myGridView;
	SingleNewsItem selectedNewsItem;
	
	String [][] myUrlAddressCaption = {
			{"Các bài mới nhất", 	 "http://www.tinsuckhoe.com/nd5/getrss.html/?param=58F0LShvOTMoPzUPIWg"},
			{"Bài nổi bật nhất", 	 "http://www.tinsuckhoe.com/nd5/getrss.html/?param=5800LShvOTMocDAxIWg"}, 
			{"Dinh dưỡng", 	 "http://www.tinsuckhoe.com/nd5/getrss.html/?param=2D00LShvX0dg"},	
			{"Phòng chữa bệnh", 	 "http://www.tinsuckhoe.com/nd5/getrss.html/?param=2D60LShvX0dm"},	
			{"Chăm sóc sức khỏe", 	 "http://www.tinsuckhoe.com/nd5/getrss.html/?param=2D10LShvX0dh"},
			{"Sử dụng thuốc", 	 "http://www.tinsuckhoe.com/nd5/getrss.html/?param=2CB0LShvX0Zl"}		
//			{"http://www.npr.org/rss/rss.php?id=1012", 	 "Politics & Society"}, 
//			{"http://www.npr.org/rss/rss.php?id=1021",   "People & Places"}, 
//			{"http://www.npr.org/rss/rss.php?id=1057",   "Opinion"}
	    }; 

    String [] myUrlAddress = {
    		"http://www.tinsuckhoe.com/nd5/getrss.html/?param=58F0LShvOTMoPzUPIWg",
    		"http://www.tinsuckhoe.com/nd5/getrss.html/?param=5800LShvOTMocDAxIWg", 
    		"http://www.tinsuckhoe.com/nd5/getrss.html/?param=2D00LShvX0dg",	
    		"http://www.tinsuckhoe.com/nd5/getrss.html/?param=2D60LShvX0dm",	
    		"http://www.tinsuckhoe.com/nd5/getrss.html/?param=2D10LShvX0dh",
    		"http://www.tinsuckhoe.com/nd5/getrss.html/?param=2CB0LShvX0Zl"
        };     
    String [] myUrlCaption = {
    		"Các bài mới nhất",
    		"Bài nổi bật nhất", 
    		"Dinh dưỡng",	
    		"Phòng chữa bệnh",	
    		"Chăm sóc sức khỏe",
    		"Sử dụng thuốc"	
        }; 
    String [] myUrlAddress2 = new String[myUrlAddressCaption.length];
    String [] myUrlCaption2 = new String[myUrlAddressCaption.length];
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.rssfeeder);
    	
    	this.setTitle("Tin tức sức khỏe");
    	myGridView = (GridView) findViewById(R.id.myGridView);
    	
    	int layoutID = R.layout.my_simple_list_item_1;
		aa = new ArrayAdapter<String>(this, layoutID , myUrlCaption);
		myGridView.setAdapter(aa);
		
    	myGridView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1, int _index,
					long id) {
				String urlAddress = myUrlAddress[_index];
                String urlCaption = myUrlCaption[_index];

				Intent NprNewsDetailsIntent = new Intent(RSSFeeder.this, NewsDetails.class);
				
				Bundle myData = new Bundle();
				myData.putString("urlAddress", urlAddress);
				myData.putString("urlCaption", urlCaption);
				NprNewsDetailsIntent.putExtras(myData);
				startActivity(NprNewsDetailsIntent);
			}
		});
    }
    
    public static String niceDate() {
	    DateFormatSymbols dfs = new DateFormatSymbols();        
	    // to get short weekday-month_name String arrays 
	    String shortWeekdaysArray[] = dfs.getShortWeekdays();
	    String shortMonthArray[] = dfs.getShortMonths();       
		Calendar cal = Calendar.getInstance(Locale.US);
		int dd = cal.get(Calendar.DAY_OF_MONTH);
		int mm = cal.get(Calendar.MONTH);
		String mmText = shortMonthArray[mm];
		int yy = cal.get(Calendar.YEAR);
		int wd = cal.get(Calendar.DAY_OF_WEEK);
		String wdText = shortWeekdaysArray[wd];
		return ( wdText + " " + mmText + " " + dd + ", " + yy );      
   }
}
